<?php

namespace Biz\model\NewProduct;


use Hhz\Mysql\BaseDbModel;

class LogisticsLogModel extends BaseDbModel
{
    public const _CONFIG_FILE_ = 'db_store';

    public const _CONFIG_SELECT_ = 'db_brand_activity';

    public const _DATABASE_ = 'brand_activity';

    public const _TABLE_NAME = 'logistics_log';

    const PENDDING = 1;//查询中：新增包裹正在查询中，请等待
    const NOTFOUND = 2;//查询不到：包裹信息目前查询不到
    const TRANSIT = 3;//运输途中：物流商已揽件，包裹正被发往目的地
    const PICKUP = 4;//到达待取：包裹正在派送中，或到达当地收发点
    const DELIVERED = 5;//成功签收：包裹已被成功投递
    const EXPIRED = 6;//运输过久：包裹在很长时间内都未投递成功。快递包裹超过30天、邮政包裹超过60天未投递成功，该查询会被识别为此状态
    const UNDELIVERED = 7;//投递失败：快递员投递失败（通常会留有通知并再次尝试投递）
    const EXCEPTION = 8;//可能异常：包裹退回、包裹丢失、清关失败等异常情况

    const STATUS_NAME_MAP = [
        self::PENDDING => '查询中',
        self::NOTFOUND => '查询不到',
        self::TRANSIT => '运输途中',
        self::PICKUP => '到达待取',
        self::DELIVERED => '成功签收',
        self::EXPIRED => '运输过久',
        self::UNDELIVERED => '投递失败',
        self::EXCEPTION => '可能异常：包裹退回、包裹丢失、清关失败等异常情况',
    ];

    public static function updateLogInfo($data, $where)
    {
        return self::update($data, $where);
    }

    /**
     * @param $status
     * @return int
     */
    public static function getStatus($status): int
    {
        switch ($status) {
            case  'pendding' :
                $status = self::PENDDING;
                break;
            case  'notfound' :
                $status = self::NOTFOUND;
                break;
            case  'transit':
                $status = self::TRANSIT;
                break;
            case  'pickup':
                $status = self::PICKUP;
                break;
            case  'delivered' :
                $status = self::DELIVERED;
                break;
            case  'expired' :
                $status = self::UNDELIVERED;
                break;
            case  'undelivered' :
                $status = self::EXPIRED;
                break;

            case  'exception' :
                $status = self::EXCEPTION;
                break;
            default :
                $status = self::TRANSIT;
        }

        return $status;
    }

}